package com.qingxin.ui.bean;

import java.util.ArrayList;
import java.util.List;

import org.codehaus.jackson.annotate.JsonIgnore;
import org.codehaus.jackson.map.annotate.JsonSerialize;

@JsonSerialize(include=JsonSerialize.Inclusion.NON_NULL)
public class UITable {

	private String idfield;
	private String pagesize;
	private String checkbox;
	private String rownumbers;
	private String sort;
	private String pager;
	private String url;
	private String rowAttrRender;
	private String autorefresh;
	private String options;
	private List<UITableColumn> columns = new ArrayList<>();
	private List<UITableColumn> operColumns = new ArrayList<>();
	
	private UITableDetail detail;
	private UIToolbar toolbar;
	
	public UITable() {
	}
	
	public UITable(String idfield, String pagesize, String checkbox,
			String rownumbers, String sort, String pager, String url,
			String rowAttrRender, String autorefresh, String options, UITableDetail detail) {
		this.idfield = idfield;
		this.pagesize = pagesize;
		this.checkbox = checkbox;
		this.rownumbers = rownumbers;
		this.sort = sort;
		this.pager = pager;
		this.url = url;
		this.rowAttrRender = rowAttrRender;
		this.autorefresh = autorefresh;
		this.options = options;
		this.detail = detail;
	}


	public UITable copy(){
		UITable target = new UITable(idfield, pagesize, checkbox, rownumbers, sort, pager, url, rowAttrRender, autorefresh, options, detail);
		
		for(int i=0, n=columns.size(); i<n; i++){
			target.addColumn(columns.get(i).copy());
		}
		
		if(toolbar!=null){
			target.setToolbar(toolbar.copy());
		}
		
		return target;
	}



	public String getIdfield() {
		return idfield;
	}
	public void setIdfield(String idfield) {
		this.idfield = idfield;
	}
	public String getPagesize() {
		return pagesize;
	}
	public void setPagesize(String pagesize) {
		this.pagesize = pagesize;
	}
	public String getCheckbox() {
		return checkbox;
	}
	public void setCheckbox(String checkbox) {
		this.checkbox = checkbox;
	}
	public String getRownumbers() {
		return rownumbers;
	}
	public void setRownumbers(String rownumbers) {
		this.rownumbers = rownumbers;
	}
	public String getSort() {
		return sort;
	}
	public void setSort(String sort) {
		this.sort = sort;
	}
	public String getPager() {
		return pager;
	}
	public void setPager(String pager) {
		this.pager = pager;
	}
	public String getUrl() {
		return url;
	}
	public void setUrl(String url) {
		this.url = url;
	}
	public String getRowAttrRender() {
		return rowAttrRender;
	}
	public void setRowAttrRender(String rowAttrRender) {
		this.rowAttrRender = rowAttrRender;
	}
	public String getAutorefresh() {
		return autorefresh;
	}
	public void setAutorefresh(String autorefresh) {
		this.autorefresh = autorefresh;
	}
	public String getOptions() {
		return options;
	}
	public void setOptions(String options) {
		this.options = options;
	}
	public void addColumn(UITableColumn column){
		columns.add(column);
		if(column.getOperItems()!=null && column.getOperItems().size()>0){
			column.setType("operlink");
			operColumns.add(column);
		}
	}
	public List<UITableColumn> getColumns() {
		return columns;
	}
	public void setColumns(List<UITableColumn> columns) {
		for(UITableColumn c : columns){
			addColumn(c);
		}
	}
	@JsonIgnore
	public List<UITableColumn> getOperColumns() {
		return operColumns;
	}
	public UITableDetail getDetail() {
		return detail;
	}
	public void setDetail(UITableDetail detail) {
		this.detail = detail;
	}
	public UIToolbar getToolbar() {
		return toolbar;
	}
	public void setToolbar(UIToolbar toolbar) {
		this.toolbar = toolbar;
	}
	
}
